﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccessLayer.DAL;
using DataAccessLayer;
using Common;
namespace BestBuy.AdminViews
{
    public partial class DeleteRegulation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            User user = UserDAL.GetUserByUsername(HttpContext.Current.User.Identity.Name);
            if (user == null || user.RoleID != (int)RoleType.Admin)
            {
                Response.Redirect("~/Account/Login.aspx");
            }
            if (!Page.IsPostBack)
            {
                cbName.DataSource = ConfigurationDAL.GetAllConfiguration();
                cbName.DataBind();

                txtDetail.Text = ConfigurationDAL.SearchDetail(int.Parse(cbName.SelectedValue.ToString()));
            }
        } 

        protected void DeleteRegulationInfoButton_Click(object sender, EventArgs e)
        {

            String name = cbName.SelectedItem.ToString();
            //string detail = Detail.SelectedValue.ToString();
            ConfigurationDAL.DeteleConfigurationDAL(name);
            AdminInfoMessage.Show("Success delete regulations.", UserControls.MessagePanel.MessageType.Success);
        }

        protected void cbName_SelectedIndexChanged(object sender, EventArgs e)
        {
            int id = int.Parse(cbName.SelectedValue.ToString());
            txtDetail.Text= ConfigurationDAL.SearchDetail(id);
        }
    }
}